#define _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    long val = LONG_MIN;
    bool isValidBST(TreeNode* root) {
        return dfs(root);
    }
    bool dfs(TreeNode* root) {
        if (root == nullptr) return true;
        bool left = dfs(root->left);
        if (left == false || root->val <= val) return false;
        val = root->val;
        bool right = dfs(root->right);
        return left && right;
    }
};